using System;
using Habanero.Base;
using Habanero.Base.Exceptions;

namespace FireStarterModeller.BO
{
    public class DMPropertyNameNotSameAsClassName : IBusinessObjectRule
    {
        private DMProperty _dmProperty;

//        public DMPropertyNameNotSameAsClassName(DMProperty dmProperty)
//        {
//            if (dmProperty == null) throw new ArgumentNullException("dmProperty");
//            _dmProperty = dmProperty;
//        }

        /// <summary>
        /// Indicates whether the property value is valid against the rules
        /// </summary>
        /// <returns>
        /// Returns true if valid
        /// </returns>
        public bool IsValid()
        {
            throw new HabaneroApplicationException("The IsValid is no longer Valid you should use the IsValid(bo) method");
        }

        public bool IsValid(IBusinessObject bo)
        {
            _dmProperty = (DMProperty) bo;
            //if (String.IsNullOrEmpty(_dmProperty.PropertyName)) return true;
            if (_dmProperty.Class == null) return true;
            return (_dmProperty.PropertyName != _dmProperty.Class.ClassNameBO); 
        }

        /// <summary>
        /// Returns the rule name
        /// </summary>
        public string Name
        {
            get { return "DMPropertyNameNotSameAsClassName"; }
        }

        /// <summary>
        /// Returns the error message for if the rule fails.
        /// </summary>
        public string Message
        {
            get { return "The Property '" + _dmProperty.ToString() + "' cannot have the same name as its Class '" + _dmProperty.Class + "'."; }
        }
        /// <summary>
        /// The <see cref="P:Habanero.Base.IBusinessObjectRule.ErrorLevel" /> for this BusinessObjectRule e.g. Warning, Error. 
        /// </summary>
        public ErrorLevel ErrorLevel
        {
            get { return Habanero.Base.ErrorLevel.Error; }
        }
    }
}